import sys
import os
import yaml
import json
import logging

def yaml_to_json(yaml_file, json_file):
    with open(yaml_file, 'r') as file:
        data = yaml.safe_load(file)
    
    with open(json_file, 'w') as file:
        json.dump(data, file, indent=2)

def convert_all_yaml_to_json(directory):
    for filename in os.listdir(directory):
        if filename.endswith(".yaml"):
            yaml_file = os.path.join(directory, filename)
            json_file = os.path.join(directory, filename.replace(".yaml", ".json"))
            yaml_to_json(yaml_file, json_file)

# 通过命令行参数获取指定路径
if len(sys.argv) == 2:
    directory = sys.argv[1]
    convert_all_yaml_to_json(directory)
else:
    logging.info("Usage: python script_name.py <directory_path>")